package jadeCW.output;

import java.util.List;

import jade.core.AID;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jadeCW.HospitalAgent;
import jadeCW.PatientAgent;

public class Printer {

	public static void printAllocateReceive(HospitalAgent hospital, AID patient) {
		print("Hospital " + hospital.getLocalName()
				+ " receives an allocate appointment request from "
				+ patient.getLocalName());
	}

	public static void printAllocateSendPropose(HospitalAgent hospital,
			AID patient, int appointment) {
		print("Hospital " + hospital.getLocalName()
				+ " proposes the appointment " + appointment + " to "
				+ patient.getLocalName());
	}

	public static void printAllocateSendRefuse(HospitalAgent hospital,
			AID patient) {
		print("Hospital " + hospital.getLocalName()
				+ " refuses to allocate an appointment to "
				+ patient.getLocalName());
	}

	public static void printFindOwnerSend(PatientAgent patient,
			int appointment, List<DFAgentDescription> hospitals) {
		StringBuilder recipients = new StringBuilder();

		for (DFAgentDescription hospital : hospitals) {
			if (recipients.length() > 0) {
				recipients.append(", ");
			}
			recipients.append(hospital.getName().getLocalName());
		}

		print("Patient " + patient.getLocalName()
				+ " requests the owner of appointment " + appointment
				+ " from " + recipients);
	}

	public static void printFindOwnerReceiveProposal(PatientAgent patient,
			int appointment, AID owner) {
		print("Patient " + patient.getLocalName()
				+ " receives the owner of appointment " + appointment + " as "
				+ owner.getLocalName());
	}
	
	public static void printFindOwnerReceiveSame(PatientAgent patient,
			int appointment) {
		print("Patient " + patient.getLocalName()
				+ " receives the same owner of appointment " + appointment + " again");
	}

	public static void printFindOwnerReceiveRefusal(PatientAgent patient,
			int appointment) {
		print("Patient " + patient.getLocalName()
				+ " is refused the owner of appointment " + appointment
				+ " (possibly the appointment does not exist)");
	}

	public static void printProposeSend(PatientAgent patient,
			int newAppointment, AID owner) {
		print("Patient " + patient.getLocalName()
				+ " sends a swap request for appointment " + newAppointment
				+ " to " + owner.getLocalName());
	}

	public static void printProposeReceiveAccept(PatientAgent patient,
			int oldAppointment, AID owner, int newAppointment) {
		print("Patient " + patient.getLocalName()
				+ " has their swap request from appointment " + newAppointment
				+ " to " + oldAppointment + " from " + owner.getLocalName()
				+ " accepted");
	}

	public static void printProposeReceiveReject(PatientAgent patient,
			int newAppointment, AID owner) {
		print("Patient " + patient.getLocalName()
				+ " has their swap request for appointment " + newAppointment
				+ " from " + owner.getLocalName()
				+ " rejected (is for them worse or they do no own it)");
	}

	public static void printProposeReceiveRefuse(PatientAgent patient,
			int newAppointment, AID owner) {
		print("Patient "
				+ patient.getLocalName()
				+ " has their swap request for appointment "
				+ newAppointment
				+ " from "
				+ owner.getLocalName()
				+ " refused temporarily (they are in the middle of their own swap)");
	}

	public static void printRTP1Receive(PatientAgent patient,
			int offeredAppointment, AID sender) {
		print("Patient " + patient.getLocalName()
				+ " receives a swap proposal from " + sender.getLocalName()
				+ " for appointment " + offeredAppointment);
	}

	public static void printRTP1SendAccept(PatientAgent patient,
			int offeredAppointment, int desiredAppointment, AID sender) {
		print("Patient " + patient.getLocalName()
				+ " accepts the swap proposal from " + sender.getLocalName()
				+ " to swap appointment " + offeredAppointment + " to " + desiredAppointment);
	}

	public static void printRTP1SendReject(PatientAgent patient,
			int offeredAppointment, int desiredAppointment, AID sender) {
		print("Patient " + patient.getLocalName()
				+ " rejects swap proposal from " + sender.getLocalName()
				+ " to swap appointment " + offeredAppointment + " to " + desiredAppointment);
	}

	public static void printRTP1SendRefuse(PatientAgent patient,
			int offeredAppointment, int desiredAppointment, AID sender) {
		print("Patient " + patient.getLocalName()
				+ " refuses swap proposal from " + sender.getLocalName()
				+ " to swap appointment " + offeredAppointment + " to " + desiredAppointment);
	}

	public static void printRTP2Receive(HospitalAgent hospital,
			int offeredAppointment, AID sender) {
		print("Hospital " + hospital.getLocalName()
				+ " receives a swap proposal from " + sender.getLocalName()
				+ " for appointment " + offeredAppointment);
	}

	public static void printRTP2SendAccept(HospitalAgent hospital,
			int offeredAppointment, AID sender) {
		print("Hospital " + hospital.getLocalName()
				+ " accepts the swap proposal from " + sender.getLocalName()
				+ " for appointment " + offeredAppointment);
	}

	public static void printRTP2SendReject(HospitalAgent hospital,
			int offeredAppointment, AID sender) {
		print("Hospital " + hospital.getLocalName()
				+ " rejects swap proposal from " + sender.getLocalName()
				+ " for appointment " + offeredAppointment);
	}

	public static void printInformSend(PatientAgent patient, int newAppointment) {
		print("Patient " + patient.getLocalName()
				+ " informs their hospitals they are swapping to appointment "
				+ newAppointment);
	}

	public static void printRequestSend(PatientAgent patient) {
		print("Patient " + patient.getLocalName() + " requests an appointment");
	}

	public static void printRequestReceiveAccept(PatientAgent patient,
			int newAppointment) {
		print("Patient " + patient.getLocalName() + " receives appointment "
				+ newAppointment);
	}

	public static void printRequestReceiveRefuse(PatientAgent patient) {
		print("Patient " + patient.getLocalName()
				+ " is refused an appointment");
	}

	public static void printRTQReceive(HospitalAgent hospital, int appointment,
			AID sender) {
		print("Hospital " + hospital.getLocalName()
				+ " receives a query for owner of appointment " + appointment
				+ " from " + sender.getLocalName());
	}

	public static void printRTQSendPropose(HospitalAgent hospital,
			int appointment, AID sender, AID owner) {
		print("Hospital " + hospital.getLocalName()
				+ " responds to query for appointment " + appointment
				+ " from " + sender.getLocalName() + " with owner: "
				+ owner.getLocalName());
	}

	public static void printRTQSendRefuse(HospitalAgent hospital,
			int appointment, AID sender) {
		print("Hospital " + hospital.getLocalName()
				+ " rejects the query for owner of appointment " + appointment
				+ " from " + sender.getLocalName());
	}

	public static void printUpdateReceive(HospitalAgent hospital,
			AID requester, AID owner, int appointment) {
		print("Hospital "
				+ hospital.getLocalName()
				+ " receives an update appointment request to swap appointment "
				+ appointment + " from " + owner.getLocalName() + " to "
				+ requester.getLocalName());
	}

	private static void print(String message) {
		System.out.println(message);
	}
}
